import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { MemberConfigService } from '../../services/admin/member-config.service';
import { MemberService } from '../../services/admin/member.service';

/**
 * ConfigController
 * 对应 PHP: Config Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('member')
@Controller('adminapi/member')
export class ConfigController {
  constructor(
    private readonly memberConfigService: MemberConfigService,
    private readonly memberService: MemberService,
  ) {}

  /**
   * 会员设置
   * 路由: GET config/login
   * PHP路由: Route::get('config/login', 'member.Config/getLoginConfig')
   */
  @Get('config/login')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async getLoginConfig(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getLoginConfig

      return await this.memberConfigService.getLoginConfig();
    } catch (error) {
      throw new BusinessException('getLoginConfig操作失败', error);
    }
  }

  /**
   * 会员设置
   * 路由: POST config/login
   * PHP路由: Route::post('config/login', 'member.Config/setLoginConfig')
   */
  @Post('config/login')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async setLoginConfig(@Body() data: SetLoginConfigDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setLoginConfig

      return await this.memberConfigService.setLoginConfig(data);
    } catch (error) {
      throw new BusinessException('setLoginConfig操作失败', error);
    }
  }

  /**
   * 会员设置
   * 路由: GET config/cash_out
   * PHP路由: Route::get('config/cash_out', 'member.Config/getCashOutConfig')
   */
  @Get('config/cash_out')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async getCashOutConfig(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getCashOutConfig

      return await this.memberConfigService.getCashOutConfig();
    } catch (error) {
      throw new BusinessException('getCashOutConfig操作失败', error);
    }
  }

  /**
   * 会员设置
   * 路由: POST config/cash_out
   * PHP路由: Route::post('config/cash_out', 'member.Config/setCashOutConfig')
   */
  @Post('config/cash_out')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async setCashOutConfig(
    @Body() data: SetCashOutConfigDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setCashOutConfig

      return await this.memberConfigService.setCashOutConfig(data);
    } catch (error) {
      throw new BusinessException('setCashOutConfig操作失败', error);
    }
  }

  /**
   * 会员设置
   * 路由: GET config/member
   * PHP路由: Route::get('config/member', 'member.Config/getMemberConfig')
   */
  @Get('config/member')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async getMemberConfig(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getMemberConfig

      return await this.memberConfigService.getMemberConfig();
    } catch (error) {
      throw new BusinessException('getMemberConfig操作失败', error);
    }
  }

  /**
   * 会员设置
   * 路由: POST config/member
   * PHP路由: Route::post('config/member', 'member.Config/setMemberConfig')
   */
  @Post('config/member')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async setMemberConfig(
    @Body() data: SetMemberConfigDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setMemberConfig

      return await this.memberConfigService.setMemberConfig(data);
    } catch (error) {
      throw new BusinessException('setMemberConfig操作失败', error);
    }
  }

  /**
   * 会员设置
   * 路由: GET config/growth_rule
   * PHP路由: Route::get('config/growth_rule', 'member.Config/getGrowthRuleConfig')
   */
  @Get('config/growth_rule')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async getGrowthRuleConfig(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getGrowthRuleConfig

      return await this.memberConfigService.getGrowthRuleConfig();
    } catch (error) {
      throw new BusinessException('getGrowthRuleConfig操作失败', error);
    }
  }

  /**
   * 会员设置
   * 路由: POST config/growth_rule
   * PHP路由: Route::post('config/growth_rule', 'member.Config/setGrowthRuleConfig')
   */
  @Post('config/growth_rule')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async setGrowthRuleConfig(
    @Body() data: SetGrowthRuleConfigDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setGrowthRuleConfig

      return await this.memberService.getGrowthRuleDict();
    } catch (error) {
      throw new BusinessException('setGrowthRuleConfig操作失败', error);
    }
  }

  /**
   * 会员设置
   * 路由: GET config/point_rule
   * PHP路由: Route::get('config/point_rule', 'member.Config/getPointRuleConfig')
   */
  @Get('config/point_rule')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async getPointRuleConfig(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getPointRuleConfig

      return await this.memberConfigService.getPointRuleConfig();
    } catch (error) {
      throw new BusinessException('getPointRuleConfig操作失败', error);
    }
  }

  /**
   * 会员设置
   * 路由: POST config/point_rule
   * PHP路由: Route::post('config/point_rule', 'member.Config/setPointRuleConfig')
   */
  @Post('config/point_rule')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '会员设置' })
  async setPointRuleConfig(
    @Body() data: SetPointRuleConfigDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setPointRuleConfig

      return await this.memberService.getPointRuleDict();
    } catch (error) {
      throw new BusinessException('setPointRuleConfig操作失败', error);
    }
  }
}
